package com.example.redisreactive.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
import org.springframework.data.redis.core.ReactiveRedisOperations;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Mono;

@Repository
public class ReactiveRedisDao {

    private final ReactiveRedisOperations<String, String> operations;

    @Autowired
    public ReactiveRedisDao(ReactiveRedisConnectionFactory factory) {
        this.operations = new ReactiveRedisTemplate<>(factory, RedisSerializationContext.string());
    }

    public Mono<Boolean> setKey(String key, String value) {
        return operations.opsForValue().set(key, value);
    }

    public Mono<String> getValue(String key) {
        return operations.opsForValue().get(key);
    }
}